<?php
require ('../include/init.inc.php');
$method = $serial_number =  '';
extract ( $_POST, EXTR_IF_EXISTS );
// echo $_POST["machine_remark"];exit;
if (Common::isPost ()) {
	$exist = Machine::getGroupBySerialNumber($serial_number);
	if($exist){
	
		OSAdmin::alert("error",ErrorMessage::EXITS_SERIAL_NUNBER);
	}else if($serial_number ==""){
		
		OSAdmin::alert("error",ErrorMessage::NEED_PARAM);
	}else{
		$allFields =  Machine::getDbField();
		foreach ($allFields  as $v){
			$key = $v["COLUMN_NAME"];
			$input_data[$key] = trim($_POST[$key]);
		}
		$input_data["create_id"] = UserSession::getUserId();
		$input_data["area_code_num"] = substr(trim($input_data["custom_code"]),0,1);
		$input_data["company_code_num"] = substr(trim($input_data["custom_code"]),2,3);
		unset($input_data["machine_id"]);
		$machine_id = Machine::addMachine ( $input_data );

		if ($machine_id) {
			SysLog::addLog ( UserSession::getUserName(), 'ADD', 'Machine' ,$machine_id, json_encode($input_data) );
			Common::exitWithSuccess ('主机添加完成','panel/machine.php');
		}
	}
}
Template::assign ( 'method', $method );
Template::assign("_POST" ,$_POST);
Template::display('panel/machine_add.tpl' );
